package main

import (
	"fmt"
)

func printArray(toPrint [5]string) {
	fmt.Println(toPrint, toPrint[3])
}
func main() {
	//var courses [10]string
	//var courses = [5]string{"django", "flask", "scrapy"}
	courses := [5]string{"django", "flask", "scrapy"}
	//1.支持修改，取值   不支持删除某个值，添加某个值
	fmt.Println(courses[0])
	courses[0] = "django3"
	fmt.Println(courses)
	fmt.Println(len(courses))
	//数组的另外一种创建方式
	//var a [4]float32
	var a = [4]float32{1, 3}
	fmt.Println(a)

	var c = [5]int{'a', 'b'}
	fmt.Println(c)

	d := [...]int{1, 2, 3, 4, 5}
	fmt.Println(d, len(d))

	e := [5]int{4: 100}
	fmt.Println(e)

	f := [5]int{0: 1, 4: 100}
	fmt.Println(f)
	//数组的操作：求长度
	fmt.Println(len(f))
	//遍历数组
	for i, value := range courses {
		fmt.Println(i, value)
	}
	sum := 0
	for _, value := range f {
		sum += value
	}
	fmt.Println(sum)
	//使用for语句也可以遍历数组
	sum = 0
	for i := 0; i < len(f); i++ {
		sum += f[i]
	}
	fmt.Println(sum)
	//数组是值类型
	var courseA = [3]string{"django", "flask", "scrapy"}
	var courseB = [...]string{"django", "flask", "scrapy", "java", "c++"}

	fmt.Println(courseA, courseB)
	fmt.Printf("%T\n", courseA)
	fmt.Printf("%T\n", courseB)
	//数组调用的时候是值传递
	printArray(courseB)

}
